//
//  ZZNetWorkRequest.h
//  ZZNetWorker
//
//  Created by ZengLiZhi on 2024/1/30.
//

#import <Foundation/Foundation.h>
#import <AFNetworking/AFNetworking.h>
#import "ZZNetWorkDecode.h"
#import "ZZNetWorkResponse.h"
#import "ZZNetWorkParamHandler.h"

//调试状态
#ifdef DEBUG
    #define ZZLog(format,...) printf("%s:(%d): %s\n", [[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__, [[NSString stringWithFormat:(format), ##__VA_ARGS__] UTF8String] )
#else
    #define ZZLog(format,...)
#endif

NS_ASSUME_NONNULL_BEGIN

typedef NS_ENUM(NSUInteger, ZZNetWorkerMethod) {
    GET = 0,
    POST = 1,
    DELETE = 2,
    PUT = 4,
    UPLOAD = 3,
    FormData = 5,
};

@class ZZNetWorker;

typedef void(^ZZNetWorkerCompletionBlock)(ZZNetWorkResponse *response, NSError * __nullable error);
typedef void (^ZZNetWorkerDidReceiveDataBlock)(NSURLSession *session, NSURLSessionDataTask *dataTask, NSData *data);

typedef void(^ZZNetWorkerUploadImageFinishBlock)(BOOL isSuccess, NSString *url);
typedef void (^ZZNetWorkerProgressBlock)(NSProgress * uploadProgress);

@interface ZZNetWorkRequest : NSObject

@property (nonatomic, assign) ZZNetWorkerMethod method;
//baseUrl
@property (nonatomic, strong) NSString *baseUrl;
@property (nonatomic, strong, readonly) ZZNetWorkRequest * (^zz_baseUrl)(NSString *baseUrl);

/// 接口api
@property (nonatomic, strong) NSString *api;
@property (nonatomic, strong, readonly) ZZNetWorkRequest * (^zz_url)(NSString *url);

/// 可选，无内部处理，用于自定义签名等
@property (nonatomic, strong) NSString *signApi;
@property (nonatomic, strong, readonly) ZZNetWorkRequest * (^zz_signApi)(NSString *signApi);

/// 获取完整url
@property (nonatomic, strong, readonly) NSString *url;

/// 请求入参
@property (nonatomic, strong) id param;
@property (nonatomic, strong, readonly) ZZNetWorkRequest * (^zz_param)(id param);

/// 测试返回数据
@property (nonatomic, strong) id testData;
@property (nonatomic, strong, readonly) ZZNetWorkRequest * (^zz_testResponse)(id data);

/// 日志开关
@property (nonatomic, assign) BOOL isOpenLog;
@property (nonatomic, strong, readonly) ZZNetWorkRequest * (^zz_log)(BOOL isOpenLog);

/// 错误弹窗
@property (nonatomic, assign) BOOL isShowErrorMessage;
@property (nonatomic, strong, readonly) ZZNetWorkRequest * (^zz_isShowErrorMessage)(BOOL isShowErrorMessage);

/// 参数处理开关
@property (nonatomic, assign) BOOL willHandlerParam;
@property (nonatomic, strong, readonly) ZZNetWorkRequest * (^zz_willHandlerParam)(BOOL willHandlerParam);

//token
@property (nonatomic, strong) NSString *authorization;
@property (nonatomic, strong, readonly) ZZNetWorkRequest * (^zz_authorization)(NSString *Authorization);

/**取消重复的请求*/
@property (nonatomic, assign) BOOL isCancelSameRequest;
@property (nonatomic, strong, readonly) ZZNetWorkRequest * (^zz_isCancelSameRequest)(BOOL b);

///处理请求参数的对象，用来加密处理等。
@property (nonatomic, strong) ZZNetWorkParamHandler *paramHandler;

///接收请求结果的model类型
@property (nonatomic, strong) Class responseClass;
@property (nonatomic, strong, readonly) ZZNetWorkRequest * (^zz_responseClass)(Class responseClass);
///接收请求结果data的model类型
@property (nonatomic, strong) Class dataClass;
@property (nonatomic, strong, readonly) ZZNetWorkRequest * (^zz_dataClass)(Class dataClass);

///请求progress回调
@property (nonatomic, strong) ZZNetWorkerProgressBlock progress;
@property (nonatomic, strong, readonly) ZZNetWorkRequest * (^zz_progress)(ZZNetWorkerProgressBlock block);

///请求完成回调
@property (nonatomic, strong) ZZNetWorkerCompletionBlock completion;
@property (nonatomic, strong, readonly) ZZNetWorkRequest * (^zz_completion)(ZZNetWorkerCompletionBlock block);

///返回数据回调
@property (nonatomic, strong) ZZNetWorkerDidReceiveDataBlock receiveData;
@property (nonatomic, strong, readonly) ZZNetWorkRequest * (^zz_receiveData)(ZZNetWorkerDidReceiveDataBlock block);

///AF设置
@property (nonatomic, strong) AFHTTPRequestSerializer <AFURLRequestSerialization> * requestSerializer;
@property (nonatomic, strong, readonly) ZZNetWorkRequest * (^zz_requestSerializer)(AFHTTPRequestSerializer <AFURLRequestSerialization> *requestSerializer);
///AF设置
@property (nonatomic, strong) AFHTTPResponseSerializer <AFURLResponseSerialization> * responseSerializer;
@property (nonatomic, strong, readonly) ZZNetWorkRequest * (^zz_responseSerializer)(AFHTTPResponseSerializer <AFURLResponseSerialization> *responseSerializer);

/// AF设置headers [request setValue:headers[headerField] forHTTPHeaderField:headerField];
@property (nonatomic, strong) NSDictionary <NSString *, NSString *> *headers;
@property (nonatomic, strong, readonly) ZZNetWorkRequest * (^zz_headers)(NSDictionary <NSString *, NSString *> *);

+ (ZZNetWorkRequest *)request;
- (ZZNetWorkResponse *)response;

@property (nonatomic, strong, readonly) NSURLSessionDataTask *task;

@property (nonatomic, strong) AFHTTPSessionManager *manager;
@end

NS_ASSUME_NONNULL_END
